package com.zh.work.service.platform.trans.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zh.work.dao.platform.trans.QrCodeTransHistoryMapper;
import com.zh.work.entity.trans.QrCodeTransTodayEntity;
import com.zh.work.entity.trans.QrCodeTransHistoryEntity;
import com.zh.work.service.platform.trans.QrCodeTransHistoryService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * code is far away from bug with the animal protecting
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃代码无BUG！
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 *
 * @Description: 二维码当天交易业务层
 * @Author: Li.HuiNeng
 * @Create in: 2019-09-10 10:38
 * @Version: 1.0.1
 */
@Service
public class QrCodeTransHistoryServiceImpl extends ServiceImpl<QrCodeTransHistoryMapper, QrCodeTransHistoryEntity> implements QrCodeTransHistoryService {
    @Autowired
    private QrCodeTransHistoryMapper qrCodeTransHistoryMapper;

    @Override
    public IPage<QrCodeTransHistoryEntity> selectQrCodeTransHistoryPages(Page<QrCodeTransHistoryEntity> page, QrCodeTransHistoryEntity param) {
        return this.qrCodeTransHistoryMapper.selectPage(
                page,
                new QueryWrapper<QrCodeTransHistoryEntity>().lambda()
                        .between(ObjectUtils.allNotNull(param.getStartDate(), param.getEndDate()),
                                QrCodeTransHistoryEntity::getTransDate, param.getStartDate(), param.getEndDate())
                        .between(ObjectUtils.allNotNull(param.getStartDate(), param.getEndDate()),
                                QrCodeTransHistoryEntity::getTransTime, param.getStartDate(), param.getEndDate())
                        .between(ObjectUtils.allNotNull(param.getAmtStart(), param.getAmtEnd()),
                                QrCodeTransHistoryEntity::getAmount, param.getAmtStart(), param.getAmtEnd())
                        .eq(StringUtils.isNotEmpty(param.getChannelCode()), QrCodeTransHistoryEntity::getChannelCode, param.getChannelCode())
                        .eq(Objects.nonNull(param.getPayType()), QrCodeTransHistoryEntity::getPayType, param.getPayType())
                        .eq(StringUtils.isNotEmpty(param.getBankNo()), QrCodeTransHistoryEntity::getBankNo, param.getBankNo())
                        .eq(Objects.nonNull(param.getStatus()), QrCodeTransHistoryEntity::getStatus, param.getStatus())
                        .eq(Objects.nonNull(param.getSettleType()), QrCodeTransHistoryEntity::getSettleType, param.getSettleType())
                        .eq(StringUtils.isNotEmpty(param.getChannelMerchNo()), QrCodeTransHistoryEntity::getChannelMerchNo, param.getChannelMerchNo())
                        .eq(Objects.nonNull(param.getNotifyStatus()),QrCodeTransTodayEntity::getNotifyStatus, param.getNotifyStatus())
                        .eq(Objects.nonNull(param.getRechargeStatus()), QrCodeTransTodayEntity::getRechargeStatus, param.getRechargeStatus())
                        .like(StringUtils.isNotEmpty(param.getOrderNo()), QrCodeTransHistoryEntity::getOrderNo, param.getOrderNo())
                        .like(StringUtils.isNotEmpty(param.getTraceNo()), QrCodeTransHistoryEntity::getTraceNo, param.getTraceNo())
                        .like(StringUtils.isNotEmpty(param.getMerchName()), QrCodeTransHistoryEntity::getMerchName, param.getMerchName())
                        .like(Objects.nonNull(param.getScanType()), QrCodeTransHistoryEntity::getScanType, param.getScanType())
                        .like(Objects.nonNull(param.getInterType()), QrCodeTransHistoryEntity::getInterType, param.getInterType())
                        .like(StringUtils.isNotEmpty(param.getMerchNo()), QrCodeTransHistoryEntity::getMerchNo, param.getMerchNo())
        );
    }
}
